package com.gcu.common.mybatisPlus.handler;


import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @ system:Mac
 * @ author:lin tingfeng
 * @ data:2023/9/20 14:25
 * @ package_name:com.gcu.common.mybatisPlus.handler
 * @ project_name:SpringCloud-Oauth2
 * @ desc: 自定义MybatisPlus处理器
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    /**
     * 新增填充创建时间和更新时间
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject,"createTime",()-> LocalDateTime.now(),LocalDateTime.class);
        this.strictInsertFill(metaObject,"updateTime",()-> LocalDateTime.now(),LocalDateTime.class);
    }

    /**
     * 更新填充更新时间
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject,"updateTime",()->LocalDateTime.now(),LocalDateTime.class);
    }
}
